package com.hmkj.admin.controller.amount;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.common.entity.export.ExportUtils;
import com.hmkj.core.model.account.AccountRechargeModel;
import com.hmkj.core.po.account.AccountRecharge;
import com.hmkj.core.service.account.AccountRechargeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(BaseController.BASE_URI)
public class AccountRechargeJsonController extends GenericController<Integer, AccountRecharge> {

    @Autowired
    private AccountRechargeService accountRechargeService;


    /**
     * 充值管理列表数据
     *
     * @param dtGridPager
     * @return
     */
    @RequestMapping(value = "/recharge/list.json", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("sys:recharge:list")
    public DtGrid listJson(String dtGridPager) throws Exception {
        dtGridPager = dataAuthority(dtGridPager);
        return accountRechargeService.getDtGridList(dtGridPager, AccountRechargeModel.class);
    }

    /**
     * 充值（人工）
     */
    @RequestMapping(value = "/recharge/save.json", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("sys:recharge:save")
    public ResultEntity recharge(AccountRecharge accountRecharge) throws Exception {
        accountRechargeService.addRechargeMoney(accountRecharge);
        return ok();
    }

    /**
     * 列表导出
     *
     * @param dtGridPager
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "recharge/export.json", method = RequestMethod.POST)
    public ResultEntity export(String dtGridPager, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 执行导出
        ExportUtils.export(request, response, accountRechargeService.getDtGridListExport(dtGridPager, AccountRechargeModel.class));
        return ok();
    }
}
